// src/main.js
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import axios from 'axios';
import { createPinia } from 'pinia';

const app = createApp(App);
const pinia = createPinia();

// 配置 axios
axios.defaults.baseURL = 'http://localhost:3000/api';
axios.interceptors.request.use(
    (config) => {
        const token = localStorage.getItem('token');
        if (token) {
            config.headers['Authorization'] = `Bearer ${token}`;
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

// 关键修改：确保 $axios 正确挂载
app.config.globalProperties.$axios = axios;

app.use(router);
app.use(pinia);
app.mount('#app');